package cn.ylz.ylmall.aftersale.controller;

import cn.ylz.ylmall.account.security.CurrentPrincipal;
import cn.ylz.ylmall.aftersale.pojo.request.AfterSaleReq;
import cn.ylz.ylmall.aftersale.service.AfterSaleService;
import cn.ylz.ylmall.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author pc
 */
@RestController
@Slf4j
@RequestMapping("/v1/AfterSale")
@Validated
@Api(tags = "6.1. 售后模块")
public class AfterSaleController {
    @Autowired
    private AfterSaleService afterSaleService;

    @PostMapping("/create")
    @ApiOperation("新增售后")
    @ApiOperationSupport(order = 601)
    public JsonResult insertOrder(@AuthenticationPrincipal CurrentPrincipal currentPrincipal,
                                  @Valid @RequestBody AfterSaleReq afterSaleReq){
        Long userId = currentPrincipal.getId();
        //返回订单号
        return JsonResult.ok(afterSaleService.insertAfterSale(afterSaleReq,userId));
    }

    @PostMapping("/select/list")
    @ApiOperation("id查询售后")
    @ApiOperationSupport(order = 602)
    public JsonResult insertOrder(@AuthenticationPrincipal CurrentPrincipal currentPrincipal){
        Long userId = currentPrincipal.getId();
        //返回订单号
        return JsonResult.ok(afterSaleService.selectAfterSale(userId));
    }

    @PostMapping("/select/page")
    @ApiOperation("分页查询售后")
    @ApiOperationSupport(order = 603)
    public JsonResult insertOrderPage(@AuthenticationPrincipal CurrentPrincipal currentPrincipal,
                                      @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Long userId = currentPrincipal.getId();
        //返回订单号
        return JsonResult.ok(afterSaleService.selectAfterSalePage(pageNum,pageSize));
    }

    @PostMapping("/delect")
    @ApiOperation("删除查询售后")
    @ApiOperationSupport(order = 604)
    public JsonResult insertOrderPage(@AuthenticationPrincipal CurrentPrincipal currentPrincipal,
                                      @RequestParam String orderNo){
        //返回订单号
        return JsonResult.ok(afterSaleService.delectByOrderNo(orderNo));
    }

}
